package qqclient.service;


import qqcommon.Message;
import qqcommon.MessageType;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Date;

//该对象提供和消息相关的服务方法
public class MessageClientService {
    public static void sendMessageToOne(String content,String getterId,String senderId)
    {
        Message message=new Message();
        message.setGetter(getterId);
        message.setContent(content);
        message.setMesType(MessageType.MESSAGE_COMM_MES);
        message.setSender(senderId);
        System.out.println(senderId+" 对 "+getterId+" 说 "+ content);
        try {
            ObjectOutputStream oos=new ObjectOutputStream(ManageClientConnectServerThread.getClientConnectServerThread(senderId).getSocket().getOutputStream());
            oos.writeObject(message);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void sendMessageToAll(String content,String senderId)
    {
        Message message=new Message();
        message.setContent(content);
        message.setMesType(MessageType.MESSAGE_TO_ALL);
        message.setSender(senderId);
        System.out.println(senderId+" 对大家说 "  + content);
        try {
            ObjectOutputStream oos=new ObjectOutputStream(ManageClientConnectServerThread.getClientConnectServerThread(senderId).getSocket().getOutputStream());
            oos.writeObject(message);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}
